<!--
 * @description  : 案件-特殊编号
 * @descriptionDetail: 案件-特殊编号
 * @copyright    : 浙江烟草
 * @author       : wxy
 * @create       : 2023-09-26 15:57:44
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar
      :is-white="false"
      :title="navTitle"
      :custom-back="goBack"
      style="z-index: 99999"
    >
      <!-- <view class="nav-right-icon">
        <span>
          <u-icon name="plus" color="#FFF" @tap="handlerAdd"></u-icon>
        </span>
        <span>
          <u-icon
            color="#FFF"
            name="more-dot-fill"
            size="38"
            @tap="selectCondit"
          ></u-icon>
        </span>
      </view> -->
    </theme-navbar>
    <!-- #endif -->
    <u-search
      class="search-space"
      shape="round"
      :clearabled="true"
      :showAction="true"
      actionText="确定"
      :animation="true"
      placeholder="请输入当事人"
      v-model="searchData.managerName"
      @custom="handlerSearch"
    ></u-search>
    <me-table
      :i="0"
      :top="10"
      :index="0"
      :load-data="loadData"
      :init-load="false"
      ref="mescrollItem0"
    >
      <template #default="d">
        <view class="card">
          <u-row @tap="handlerSelectItem(d.data)">
            <u-col span="10">
              <codeListItem :isClick="false" :client="d.data"></codeListItem>
            </u-col>
            <u-col span="2" style="text-align: right">
              <u-icon
                name="checkbox-mark"
                :color="$theme.u_type_primary"
                size="38"
                style="margin-right: 10px"
                v-if="selectedUids.includes(d.data.jgsxDealUuid)"
              ></u-icon>
            </u-col>
          </u-row>
        </view>
      </template>
    </me-table>
    <!-- 底部按钮开始 -->
    <view class="submit-btns btn-other-cls">
      <u-button class="u-btn" type="primary" @click="handlerSure">
        确定
      </u-button>
    </view>
  </view>
</template>

<script>
import MeTable from "@/components/me-table.vue";
import MescrollMoreMixin from "@/components/mescroll-uni/mixins/mescroll-more.js";
import checkService from "@/service/case/case.service";
import codeListItem from "./codeListItem.vue";
import OrgSelect from "@/components/org-select.vue";
export default {
  components: {
    MeTable,
    codeListItem,
  },
  mixins: [MescrollMoreMixin,],
  data() {
    return {
      searchData:{
        dealType: "22",
      },
      isSingle: true, // 是否单选，默认多选
      selectedUids: [], // 选中项的ids
      selectedItems: [], // 选中项
      planList: [],
      newList: [],
      searchObj: {}, // 返回过来查询对象
      queryShow: false,
      orgSelectShow: false,
      isReportHotline: false,
      typeShow: false,
      applyCode: "",
    };
  },
  onLoad(option) {
    // 增加日期查询，迁移数据后数据量比较大
    this.searchData.checkDateBegin = this.$u.date(new Date(new Date().getTime() - 8 * 24 * 3600 * 1000), 'yyyy-mm-dd') + ' 00:00:00';
    this.searchData.checkDateEnd = this.$u.date(new Date(), 'yyyy-mm-dd') + ' 23:59:59';
    console.log(this.searchData);
  },
  methods: {
    setRightBtns() {
      // 设置右侧标题
      // #ifdef H5-DINGDING
      this.$deviceApi.setMenu(
        [
          { id: "1", text: "添加", },
          { id: "2", text: "筛选", },
        ],
        (res) => {
          if (res.id == "1") {
            // 添加
            this.handlerAdd();
          } else {
            // 筛选
            this.selectCondit();
          }
        }
      );
      // #endif
    },
    handlerSearch() {
      let mescroll = this.getMescroll(0);
      mescroll && mescroll.triggerDownScroll();
    },
    // 选中
    handlerSelectItem(item) {
      if (this.isSingle) {
        this.selectedUids = [item.jgsxDealUuid,];
        this.selectedItems = [item,];
        return;
      }
    },
    loadData(page) {
      return new Promise((resolve, reject) => {
        checkService.jgsxCheckLst({
          page: page.num,
          limit: page.size,
          paras: {...this.searchData,},
        }).then(res => {
          if(res.success){
            resolve({
              count: res.data.length,
              data:res.data,
            });            
          }else{
            this.$u.toast(res.msg);
            resolve({
              count: 0,
              data:[],
            });
          }
        }).catch(err => {
          this.$u.toast(err);
          resolve({
            count: 0,
            data:[],
          });
        });
      });
    },
    // 确定
    handlerSure() {
      let self = this;
      // 零售户添加
      if (this.selectedItems.length == 0) {
        this.$u.toast("请选择检查编号");
        return;
      }
      this.planList.forEach((item) => {
        self.newList.push(item.jgsxDealUuid);
      });
      let idList = self.selectedItems.filter((r) => {
        return self.newList.includes(r.jgsxDealUuid);
      });
      if (idList.length > 0) {
        this.$u.hideLoading();
        this.selectedItems.filter((item) => {
          if (item.jgsxDealUuid == idList[0].jgsxDealUuid) {
            this.$u.toast(`【${item.areaName}】已存在`);
          }
        });
        return;
      }
      this.backPrev({
        paramKey: "actionCodeList",
        param: this.selectedItems[0],
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.page {
  padding: 0;
}
.sticky-header {
  background-color: #fff;
  position: fixed;
  /* #ifdef H5-DINGDING  */
  top: 0px;
  /* #endif */
  /* #ifndef H5-DINGDING  */
  top: 44px;
  /* #endif */
  width: 100%;
  height: 40px;
  z-index: 999;
}
.search-space{
	padding: $cm-search-padding-row $cm-search-padding-column;
	padding-bottom: 6px;
}

</style>
